using System.ComponentModel;

namespace WB.Mvc.Forms
{
	/// <summary>
	/// Strategy that creates <see cref="BooleanField"/>.
	/// </summary>
	public class BooleanFieldStrategy : IFieldStrategy
	{
		/// <summary>
		/// Creates a <see cref="Field"/>.
		/// </summary>
		public Field Create(string name)
		{
			return new BooleanField(name);
		}
	}

	/// <summary>
	/// Strategy that creates a <see cref="Field"/> from a <see cref="bool"/> <see cref="PropertyDescriptor"/>.
	/// </summary>
	public class BoolToBooleanFieldStrategy: BooleanFieldStrategy, IModelFieldStrategy
	{
		/// <summary>
		/// Creates a <see cref="Field"/> from <paramref name="descriptor"/>.
		/// </summary>
		/// <param name="descriptor">
		/// Model for <see cref="Field"/>.
		/// </param>
		/// <returns>
		/// <see cref="Field"/> if <paramref name="descriptor.PropertyType"/> 
		/// is <see cref="bool"/>; <c>null</c> otherwise.
		/// </returns>
		public Field Create(PropertyDescriptor descriptor)
		{
			if (descriptor.PropertyType == typeof(bool))
				return Create(descriptor.Name);
			return default(Field);
		}
	}
}